package com.jgdt.jgdtkasannong_university_gene_backend.service.content.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jgdt.jgdtkasannong_university_gene_backend.common.response.PageRequest;
import com.jgdt.jgdtkasannong_university_gene_backend.dto.ContenMediaDto;
import com.jgdt.jgdtkasannong_university_gene_backend.entity.content.ContentGeneral;
import com.jgdt.jgdtkasannong_university_gene_backend.mapper.content.ContentGeneralMapper;
import com.jgdt.jgdtkasannong_university_gene_backend.service.content.ContentGeneralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 内容表 服务实现类
 * </p>
 *
 * @author chenzg
 * @since 2025-04-24
 */
@Service
public class ContentGeneralServiceImpl extends ServiceImpl<ContentGeneralMapper,ContentGeneral> implements ContentGeneralService {

    @Autowired
    private ContentGeneralMapper contentGeneralMapper;

    @Override
    public List<ContenMediaDto> contenMediaByMenuIds(List<Integer> menuIds){
        return contentGeneralMapper.contenMediaByMenuIds(menuIds);
    }

    @Override
    public IPage<ContenMediaDto> contenMediaPage(PageRequest<ContenMediaDto> page) {
        Page<ContenMediaDto> contenMediaDtoPage=new Page<ContenMediaDto>(page.getPageNum(),page.getPageSize());
        ContenMediaDto contenMediaDto=new ContenMediaDto();
        if(page.getCondition().getMediaId()!=null){
            contenMediaDto.setMenuId(page.getCondition().getMediaId());
        }
        return contentGeneralMapper.contenMediaPage(contenMediaDtoPage,contenMediaDto);
    }

    @Override
    public List<ContentGeneral> queryByGeneralIds(List<Integer> contentIds) {
        if (CollectionUtil.isEmpty(contentIds)){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<ContentGeneral> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.in(ContentGeneral::getId,contentIds);
        return contentGeneralMapper.selectList(queryWrapper);
    }

    @Override
    public void saveUpdateById(List<ContentGeneral> contentGenerals) {
        this.saveOrUpdateBatch(contentGenerals);
    }
}
